package api

import (
	__ "api-gateway/basic/activity_proto"
	"api-gateway/basic/inits"
	"api-gateway/handler/request"
	"api-gateway/handler/response"
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
)

// SetFaceId 设置用户面容ID

func SetFaceId(c *gin.Context) {
	var req request.SetFaceId
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	fmt.Println(req)
	resp, err := inits.ActivityClient.SetFaceId(c, &__.SetFaceIdReq{
		UserId:    req.UserId,
		FaceToken: req.FaceToken,
		FaceData:  req.FaceData,
		Status:    int32(req.Status),
	})
	log.Println(resp)
	if err != nil {
		response.Error(c, 500, "设置面容ID失败", err.Error())
		return
	}
	response.Success(c, "成功", resp)
}

// 获取面容id
func GetFaceId(c *gin.Context) {
	var req request.GetFaceId
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	resp, err := inits.ActivityClient.GetFaceId(c, &__.GetFaceIdReq{
		UserId: req.UserId,
	})
	if err != nil {
		response.Error(c, 500, "获取面容ID失败", err.Error())
		return
	}
	response.Success(c, "成功", resp)
}

func UpdateFaceIdStatus(c *gin.Context) {
	var req request.UpdateFaceIdStatus
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	resp, err := inits.ActivityClient.GetFaceId(c, &__.GetFaceIdReq{
		UserId: req.UserId,
	})
	if err != nil {
		response.Error(c, 500, "获取面容ID失败", err.Error())
		return
	}
	response.Success(c, "成功", resp)
}

// 删除面容id

func DeleteFaceId(c *gin.Context) {
	var req request.DeleteFaceId
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	resp, err := inits.ActivityClient.DeleteFaceId(c, &__.DeleteFaceIdReq{
		UserId: req.UserId,
	})
	if err != nil {
		response.Error(c, 500, "删除面容ID失败", err.Error())
		return
	}
	response.Success(c, "成功", resp)
}

// 验证面容id

func VerifyFaceId(c *gin.Context) {
	var req request.VerifyFaceId
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	resp, err := inits.ActivityClient.VerifyFaceId(c, &__.VerifyFaceIdReq{
		UserId:    req.UserId,
		FaceToken: req.FaceToken,
	})
	if err != nil {
		response.Error(c, 500, "验证面容ID失败", err.Error())
		return
	}
	response.Success(c, "成功", resp)
}
